package com.tcu.menu.controller;

import com.tcu.menu.entity.Menu;
import com.tcu.menu.entity.MenuItem;
import com.tcu.menu.mapper.MenuMapper;
import com.tcu.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuMapper menuMapper;

    @GetMapping("list")
    public R list(){
        List<Menu> menus = menuMapper.selectList(null);
        menus.forEach(m->{
            List<MenuItem> itemListByMenuIt = menuMapper.getItemListByMenuIt(m.getId().toString());
            m.setChildren(itemListByMenuIt);
        });
        return R.success().data("userMenu", menus);
    }
}
